package com.cherrish;

import io.grpc.stub.StreamObserver;
import net.devh.springboot.autoconfigure.grpc.server.GrpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author cherrish
 * @time 2018-09-03 15:55
 * @name UserGrpcService
 * @desc:
 */
@GrpcService(UserServiceGrpc.class)
public class UserGrpcService extends UserServiceGrpc.UserServiceImplBase {

    private Logger logger = LoggerFactory.getLogger(UserGrpcService.class);

    @Override
    public void addUser(User request, StreamObserver<BooleanReply> responseObserver) {
        logger.info("User={id={}, username={}, address={}, age={}, sex={}, createtime={}, updatetime={}}",
                request.getId(), request.getUsername(), request.getAddress(), request.getAge(), request.getSex(), request.getCreatetime(), request.getUpdatetime());

        //TODO 可以自定义实现
        BooleanReply replay = BooleanReply.newBuilder().setReply(true).build();
        responseObserver.onNext(replay);
        responseObserver.onCompleted();
    }
}
